

#include "meshInspector.h"
#include "renderer.h"

MeshInspector::MeshInspector(){

    bOpen=false;
    bPermanent=true;
    initialLocation=location;
    tabWidth=350;
    listHeight=64;
    listWidth=64;
    listDisplayMode=4;
    listColumns=4;
    level=0;
    textureID="icon_props";
    }

MeshInspector::~MeshInspector(){}


void MeshInspector::setup(){
ListButton::setup();

}

void MeshInspector::update(double deltaTime){

    if (listButton.size()<renderer->vboList.size()){
        ListButton::deselect(level);
        listButton.clear();
        assembleList();
    }


}

void MeshInspector::mouseOver(){

ListButton::mouseOver();
}


void MeshInspector::drawPlane(){

    Button::drawPlane();

    renderer->setupShading("color");
    if (bOpen){
        renderer->drawPlane(scale.x ,0.0, scale.x+tabWidth,renderer->screenY, Vector4f(0.4,0.4,0.4, 1.0));
    }

}


void MeshInspector::mouseDrag(){}

void MeshInspector::clickedLeft(){

    if (!bOpen){
        initialLocation=location;
        location.x-=tabWidth;
        for (uint i=0;i<listButton.size();i++)
            {
            listButton[i]->location.x-=tabWidth;
            listButton[i]->initialLocation.x=listButton[i]->location.x;
            }
        ListButton::clickedLeft();
        bOpen=true;
        ListButton::clickedLeft();
    }
    else{
        for (uint i=0;i<listButton.size();i++)
            listButton[i]->location.x+=initialLocation.x-location.x;
        location=initialLocation;
        bOpen=false;
        ListButton::deselect(level);
        listButton.clear();
        assembleList();
    }

    cout << "my listSize is: " << listButton.size() << endl;
}


void MeshInspector::assembleList(){

        cout << "assembling mesh list..." << endl;
        std::map <std::string, complexMesh*>::iterator it;
        int i=0;

        for ( it=renderer->vboList.begin() ; it != renderer->vboList.end(); it++ ){

            if (it->first!="NULL"){

                cout << "creating button for... " << it->first << endl;
                renderer->actorInfo["17CreateActorButton"].actorReference->create();
                listButton.push_back(renderer->buttonList.back());

                listButton[i]->name="string " + it->first;
                cout << "Name is:" << it->first << endl;
                listButton[i]->vboMeshID=it->first;
                if (renderer->vboList[it->first]->bIsSkeletal){
                    if (renderer->vboList[it->first]->bIsHead)
                        listButton[i]->buttonProperty="12SkeletalHead";
                    else
                        listButton[i]->buttonProperty="13SkeletalActor";
                    }
                else
                    listButton[i]->buttonProperty="5Actor";
                listButton[i]->textureID="icon_base";
                listButton[i]->level=level+1;
                listButton[i]->bDrawName=true;
                listButton[i]->color=Vector4f(1,0.6,0.6,1.0);
                listButton[i]->bPermanent=true;
                listButton[i]->bDragable=true;
                listButton[i]->setup();
                placeButton(i,i);
                //set this because we want to drag buttons around!
                listButton[i]->initialLocation=listButton[i]->location;

                i++;
            }
        }

    //cout << "our Button list is: "<< listButton.size() <<" elements long..." << endl;
}


void MeshInspector::clickedRight(){}
void MeshInspector::focusClick(){

ListButton::focusClick();
}

void MeshInspector::deselect(int depth){

//ListButton::deselect(depth);
}

void MeshInspector::create(){renderer->addButton(this);}
